"use strict";
cc._RF.push(module, '8643bqziE9E5pwwD3C6UvTi', 'TweenAnim');
// scripts/Game/Obj/TweenAnim.ts

"use strict";
var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
var ActionType;
(function (ActionType) {
    ActionType[ActionType["rotate"] = 0] = "rotate";
    ActionType[ActionType["shake"] = 1] = "shake";
    ActionType[ActionType["scale"] = 2] = "scale";
    ActionType[ActionType["alpha"] = 3] = "alpha";
})(ActionType || (ActionType = {}));
// enum EaseType{
//     Line = "",
//     Sin = "sineInOut",
// }
var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property, menu = _a.menu, disallowMultiple = _a.disallowMultiple, executionOrder = _a.executionOrder, requireComponent = _a.requireComponent;
// 这个类用来写动作
var TweenAnim = /** @class */ (function (_super) {
    __extends(TweenAnim, _super);
    function TweenAnim() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.actionType = ActionType.rotate;
        _this.isAutoStart = true;
        _this.maxTime = .5;
        _this.minTime = .5;
        _this.maxScale = 1.1;
        _this.minScale = 0.9;
        _this.maxAlpha = 255;
        _this.minAlpha = 0;
        _this.inverse = false;
        // LIFE-CYCLE CALLBACKS:
        _this.startPosX = 0;
        _this.startPosY = 0;
        _this.startAngle = 0; // 初始角度
        _this.isRun = false;
        return _this;
        // update (dt) {}
    }
    TweenAnim.prototype.onLoad = function () {
        this.startPosX = this.node.x;
        this.startPosY = this.node.y;
        this.startAngle = this.node.angle;
        if (this.isAutoStart) {
            this.runAction();
        }
    };
    TweenAnim.prototype.start = function () {
        if (this.isAutoStart) {
            this.runAction();
        }
    };
    TweenAnim.prototype.onStart = function () {
        this.runAction();
    };
    TweenAnim.prototype.runAction = function () {
        if (this.isRun) {
            return;
        }
        this.isRun = true;
        this.node.stopAllActions();
        var tween = cc.tween(this.node);
        if (this.actionType == ActionType.rotate) {
            this.node.runAction(cc.repeatForever(cc.rotateBy(0.1, this.inverse ? 10 : -10)));
        }
        else if (this.actionType == ActionType.shake) {
            var time = 0.1;
            var offset = 10;
            var action1 = cc.rotateBy(time, offset);
            var action2 = cc.rotateBy(time, -offset * 2);
            var action3 = cc.rotateBy(time, offset * 2);
            var action4 = cc.rotateBy(time, -offset * 2);
            var action5 = cc.rotateBy(time, offset * 2);
            var action6 = cc.rotateBy(time, -offset);
            var action7 = cc.delayTime(0.5);
            var repeat1 = cc.repeatForever(cc.sequence(action1, action2, action3, action4, action5, action6, action7));
            this.node.runAction(repeat1);
        }
        else if (this.actionType == ActionType.scale) {
            tween.repeatForever(tween.sequence(tween.to(this.maxTime, { scale: this.maxScale }, { easing: 'sineInOut' }), tween.to(this.minTime, { scale: this.minScale }, { easing: 'sineInOut' }))).start();
        }
        else if (this.actionType == ActionType.alpha) {
            tween.repeatForever(tween.sequence(tween.to(this.maxTime, { opacity: this.maxAlpha }, { easing: 'sineInOut' }), tween.to(this.minTime, { opacity: this.minAlpha }, { easing: 'sineInOut' }))).start();
        }
    };
    TweenAnim.prototype.onStop = function () {
        this.isRun = false;
        this.node.stopAllActions();
        this.node.x = this.startPosX;
        this.node.y = this.startPosY;
        this.node.angle = this.startAngle;
        this.node.scale = 1;
        this.node.opacity = 255;
    };
    __decorate([
        property({ type: cc.Enum(ActionType), displayName: "动作类型" })
    ], TweenAnim.prototype, "actionType", void 0);
    __decorate([
        property({ displayName: "是否立即开始" })
    ], TweenAnim.prototype, "isAutoStart", void 0);
    __decorate([
        property({ type: cc.Float, displayName: "前往最大值的时间", visible: function () { return this.actionType !== ActionType.shake; } })
    ], TweenAnim.prototype, "maxTime", void 0);
    __decorate([
        property({ type: cc.Float, displayName: "前往最小值的时间", visible: function () { return this.actionType !== ActionType.shake; } })
    ], TweenAnim.prototype, "minTime", void 0);
    __decorate([
        property({ type: cc.Float, displayName: "最大值", visible: function () { return this.actionType == ActionType.scale; } })
    ], TweenAnim.prototype, "maxScale", void 0);
    __decorate([
        property({ type: cc.Float, displayName: "最小值", visible: function () { return this.actionType == ActionType.scale; } })
    ], TweenAnim.prototype, "minScale", void 0);
    __decorate([
        property({ type: cc.Integer, displayName: "透明度最大值", visible: function () { return this.actionType == ActionType.alpha; } })
    ], TweenAnim.prototype, "maxAlpha", void 0);
    __decorate([
        property({ type: cc.Integer, displayName: "透明度最小值", visible: function () { return this.actionType == ActionType.alpha; } })
    ], TweenAnim.prototype, "minAlpha", void 0);
    __decorate([
        property({ displayName: "反向", visible: function () { return this.actionType == ActionType.rotate; } })
    ], TweenAnim.prototype, "inverse", void 0);
    TweenAnim = __decorate([
        ccclass
        //@disallowMultiple() //防止多个相同类型（或子类型）的组件被添加到同一个节点
        ,
        menu('工具组件/TweenAnim')
    ], TweenAnim);
    return TweenAnim;
}(cc.Component));
exports.default = TweenAnim;

cc._RF.pop();